package com.starmark.gateway.project.provider.web;


import com.starmark.auth.common.util.UserUtil;
import com.starmark.core.framework.base.AbstractController;
import com.starmark.core.framework.util.BeanMapper;
import com.starmark.core.framework.vo.PageQueryVo;
import com.starmark.gateway.project.provider.service.IGatewayProjectService;
import com.starmark.gateway.project.provider.vo.GatewayProjectPageVo;
import com.starmark.gateway.project.provider.vo.GatewayProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author starmark
 * @since 2018-04-27
 */
@RestController

@Api(value = "系统工程信息", description = "系统工程")
@RequestMapping("/gateway/project")
public class GatewayProjectController extends AbstractController {

    @Autowired
    private IGatewayProjectService gatewayAuthProjectService;


    @ApiOperation(value = "查看系统权限工程详情")
    @GetMapping(value = "/get/{id}")
    public GatewayProjectVo get(@PathVariable("id") String id) {
        return gatewayAuthProjectService.getGatewayAuthProjectVoById(id);
    }

    @GetMapping(value = "/getByProjectCode/{projectCode}")
    public GatewayProjectVo getByProjectCode(@PathVariable("projectCode") String projectCode) {
        return gatewayAuthProjectService.getGatewayAuthProjectVoByProjectCode(projectCode);
    }

    @PostMapping(value = "/save")
    @ApiOperation(value = "保存系统工程资源")
    public GatewayProjectVo saveOrUpdate(@RequestBody GatewayProjectVo gatewayProjectVo) {

        return gatewayAuthProjectService.saveOrUpdateProject(gatewayProjectVo);
    }

    @ApiOperation(value = "查询系统权限工程列表")
    @PostMapping(value = "/query")
    public Object query(@RequestBody PageQueryVo pageQueryVo) {
        return BeanMapper.mapPage(gatewayAuthProjectService.selectProjectPage(pageQueryVo, UserUtil.getCurrentUser()), GatewayProjectPageVo.class);
    }

    @DeleteMapping(value = "/{id}")
    @ApiOperation(value = "删除网关工程")
    public void delete(@PathVariable("id") String id) {

        gatewayAuthProjectService.removeById(id);
    }

}
